package com.dabai.iot.core.tsl.specs;

import com.dabai.iot.core.entity.ThingModelItemEntity;
import com.dabai.iot.core.tsl.TslPropDataType;

import java.util.HashMap;
import java.util.Map;

/**
 * 物模型属性描述帮助类
 *
 * @author kev1n
 */
public class TslDataSpecHelper {

    private static final Map<String, TslDataSpec> SPECS = new HashMap<>();

    static {
        SPECS.put(TslPropDataType.INT32.getType(), new TslIntSpec());
        SPECS.put(TslPropDataType.FLOAT.getType(), new TslFloatSpec());
        SPECS.put(TslPropDataType.BOOL.getType(), new TslBoolSpec());
        SPECS.put(TslPropDataType.TEXT.getType(), new TslTextSpec());
    }

    /**
     * 获取 map
     */
    public static Map<String, TslDataSpec> getSpecs() {
        return SPECS;
    }

    public static TslDataSpec getSpec(String dataType) {
        return SPECS.get(dataType);
    }

    // 统一创建数据规格的方法
    public static TslDataSpec createDataSpecs(ThingModelItemEntity item) {
        TslDataSpec spec = getSpec(item.getDataType());
        return spec != null ? spec.createSpec(item) : null;
    }

}
